package com.leetcode.array.binarysearch.demo5;

/**
 * @Author Zan
 * @Create 2024/5/8 10:21
 * @ClassName: Test
 * @Description : https://leetcode.cn/problems/valid-perfect-square/   有效的完全平方数
 */
public class Test {
    public static void main(String[] args) {

    }
}

class Solution {
    public boolean isPerfectSquare(int num) {
        int left = 0;
        int right = num;
        while (left <= right) {
            int mid = (left + right) / 2;
            if ((long) mid * mid == num) {
                return true;
            } else if ((long) mid * mid < num) {
                left = mid + 1;
            } else if ((long) mid * mid > num) {
                right = mid - 1;
            }
        }
        return false;
    }
}